/*
Copyright 2008  Four Roads LLC conact@4-roads.com

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either 
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CA = ComponentArt.Web.UI;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;

namespace FourRoads.Links.Controls
{
	public class SectionEditControl : BaseControl
	{
		#region Public Properties

		private int sectionID = -1;
		public int SectionID
		{
			get { return sectionID; }
			set { sectionID = value;}
		}


		private ResLinkSection section;
		public ResLinkSection Section
		{
			get {return section;}
			set {section = value;}
		}

		#endregion

		#region Child Controls
		
		protected CA.TabStrip SettingTabs;
		protected SectionEditDetailsControl SectionDetails1;
		protected SectionPermissionListControl SectionPermissions1;
		protected ControlPanelSelectedNavigation SelectedNavigation1;
		protected DirectoryWriter SectionDirectoryWriter;
		#endregion

		override protected void OnInit(EventArgs e)
		{
			this.Load += new EventHandler(this.Page_Load);
			base.OnInit(e);
		}

		private void Page_Load(object sender, EventArgs e)
		{
			SectionDetails1.SectionID = SectionPermissions1.SectionID = SectionID;			
		}

		public bool Save()
		{
			if(!Page.IsValid)
				return false;

			if(!SectionDetails1.Save())
				return false;
			
			SectionPermissions1.SectionID = SectionDetails1.SectionID;
			SectionPermissions1.Save();
		
			if(!Page.IsValid)
				return false;

			ResLinkSection.ClearSectionCache(SectionID);

			return true;
		}

	}
}
